//
//  TTSCustomTabBarViewController.m
//  TTSVideo
//
//  Created by chenHR on 16/2/29.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "TTSCustomTabBarViewController.h"
#import "TTSCustomTabBarButton.h"
#import "TTSCustomTabBarView.h"

@interface TTSCustomTabBarViewController ()<TTSCustomTabBarViewDelegate>


@end

@implementation TTSCustomTabBarViewController

- (void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    [self TTSCreateTabBarButton];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    // 删除tabbar
    //    CGRect rect = self.tabBar.bounds;
    self.tabBar.translucent = NO;
    
}

- (void)TTSCreateTabBarButton{
    
    // 添加自定义tabbar
    TTSCustomTabBarView *tabBarView = [[TTSCustomTabBarView alloc] init];
    tabBarView.tabBarDelegate = self;
    tabBarView.backgroundColor = [UIColor whiteColor];
    tabBarView.frame = self.tabBar.frame;
    
    // 添加按钮
    NSInteger count = self.viewControllers.count; // 子视图控制器的个数
    NSMutableArray *titleArray = [NSMutableArray arrayWithObjects:@"每日精选", @"发现更多", @"热门排行", nil];
    for (int i = 0; i < count; i++) {
        
        NSString *title = [titleArray objectAtIndex:i];
        [tabBarView TTSAddButtonWithTitle:title color:[UIColor colorWithWhite:0.447 alpha:1.000] selecterColor:[UIColor blackColor]];
        
    }
    
    [self.view addSubview:tabBarView];

}

/**
 *  实现协议代理方法(控制页面的跳转)
 */
- (void)TTSTabBar:(TTSCustomTabBarView *)tabbar selectedFromFlag:(NSInteger)fromFlag toFlag:(NSInteger)toFlag{
    self.selectedIndex = toFlag;
}

/**
 *  TabBar的frame
 */
- (void)viewWillLayoutSubviews{
//    [super viewWillLayoutSubviews];
    CGRect tabBarFrame = self.tabBar.bounds;
    tabBarFrame.size.height = 36;
    tabBarFrame.origin.y = self.view.frame.size.height - 36;
    self.tabBar.frame = tabBarFrame;
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
